<?php
class Paramadmin_Model_Rules extends Zend_Db_Table_Abstract
{
    protected $_name = 'rule';
    protected $_primary = 'idrule';
    protected $_adapter = 'db2';
    
    protected function _setupDatabaseAdapter(){
        $this->_db = Zend_Registry::get($this->_adapter);
    }


    public function getrules($start = 0, $limit = 0){
        
        $data = array();
        $limit = ($limit != 0)?'LIMIT '.$start.', '.$limit:'';
        
        $sql = sprintf("select SQL_CALC_FOUND_ROWS r.idrule, r.idsystem, r.rulename, r.ruledesc, case isnull(r.dinactive) WHEN 1 THEN 'Activo' ELSE 'Inactivo' END as dinactive FROM rule r %s", $limit);

        //$db = $this->getDefaultAdapter();
        $db = Zend_Registry::get('db2');
        $stmt = $db->query($sql);
        $data = $stmt->fetchAll();
        
        $sql = 'SELECT FOUND_ROWS()';
        $stmt = $db->query($sql);
        $total = $stmt->fetchColumn();
               
        $result = array(
            'data' => $data,
            'total' => $total
        ); 
        
        return $data;
    }   

}



?>